package sz.szsmk.citizencard.ui.adapter;

import android.content.Context;
import android.os.Bundle;
import androidx.fragment.app.FragmentActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.seapeak.recyclebundle.BaseHolder;
import com.seapeak.recyclebundle.BaseRecyclerAdapter;

import java.util.List;

import sz.szsmk.citizencard.databinding.BusSiteNearbyItemBinding;
import sz.szsmk.citizencard.model.network.bean.response.QueryNearStandbyRes;
import sz.szsmk.citizencard.util.JumpUtils;

/**
 * Copyright (c)2018
 * author: zdh
 * created on: 2018/11/16 10:54
 * description:
 */
public class BusSiteNearbyAdapter extends BaseRecyclerAdapter<BusSiteNearbyAdapter.BusSiteNearbyHolder> {

    private RecyclerView busSiteRv;
    private Context mContext;
    private BusSiteTvitemAdapter tvitemAdapter;
    private List<QueryNearStandbyRes.BusSiteListBean> viewData;
    private QueryNearStandbyRes.BusSiteListBean busSiteListBean;

    public BusSiteNearbyAdapter(FragmentActivity activity) {
        mContext = activity;

    }

//    @Override
//    public int getItemViewType(int position) {
//        return R.layout.bus_site_nearby_item;
//    }

    @Override
    public BusSiteNearbyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return BusSiteNearbyHolder.creat(parent);
    }

    @Override
    public void onBindViewHolder(BusSiteNearbyHolder holder, int position) {
        loadItemData(position, holder.binding);
    }

    private void loadItemData(int position, BusSiteNearbyItemBinding binding) {
        if (viewData!=null){
            final String stand_name = viewData.get(position).getStand_name();
            final String stand_guid = viewData.get(position).getStand_guid();
            binding.busSiteLl.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Bundle bundle = new Bundle();
                    bundle.putString("stand_name",stand_name);
                    bundle.putString("stand_guid",stand_guid);
                    JumpUtils.jumptoNatvie(mContext, "BusSiteDetailActivity", 0,bundle);
                }
            });
            busSiteListBean = viewData.get(position);
            busSiteRv = binding.busSiteTv;
            binding.busSiteDistance.setText(busSiteListBean.getDistance());
            binding.busSiteEnd.setText(busSiteListBean.getStand_name());
//            binding.siteLinelist.setText(busSiteListBean.getStand_cross_line());

            binding.busSiteDistance.setText(busSiteListBean.getRoad());

            LinearLayoutManager manager = new LinearLayoutManager(mContext);
            manager.setOrientation(LinearLayoutManager.HORIZONTAL);
            busSiteRv.setLayoutManager(manager);

            tvitemAdapter = new BusSiteTvitemAdapter(mContext);
            busSiteRv.setAdapter(tvitemAdapter);
            tvitemAdapter.setViewData(busSiteListBean.getBusInfos());
        }
    }

    @Override
    public int getItemCount() {
        return null == viewData ? 0 : viewData.size();
    }


    public void setViewData(List<QueryNearStandbyRes.BusSiteListBean> viewData) {
        this.viewData = viewData;
    }

    public static class BusSiteNearbyHolder extends BaseHolder {
        private BusSiteNearbyItemBinding binding;

        public static BusSiteNearbyHolder creat(ViewGroup parent) {
            BusSiteNearbyItemBinding binding = BusSiteNearbyItemBinding
                    .inflate(LayoutInflater.from(parent.getContext()), parent, false);
            return new BusSiteNearbyHolder(binding);
        }


        public BusSiteNearbyHolder(BusSiteNearbyItemBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
    }

}
